<?php
// 这是添加客户数据的PHP文件
// 获取前端传递的数据
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$occupation = $_POST['occupation'];
$idType = $_POST['idType'];
$idNumber = $_POST['idNumber'];
$address = $_POST['address'];
$other = $_POST['other'];
// 引用数据库连接文件
require_once 'databaseConnection.php';

try {
  $conn = connectToDatabase(); // 连接数据库

  // 将数据插入到数据库
  $sql = "INSERT INTO customers (name, email, phone, occupation, idType, idNumber, address, other)
          VALUES (:name, :email, :phone, :occupation, :idType, :idNumber, :address, :other)";

  $stmt = $conn->prepare($sql);
  $stmt->bindParam(':name', $name);
  $stmt->bindParam(':email', $email);
  $stmt->bindParam(':phone', $phone);
  $stmt->bindParam(':occupation', $occupation);
  $stmt->bindParam(':idType', $idType);
  $stmt->bindParam(':idNumber', $idNumber);
  $stmt->bindParam(':address', $address);
  $stmt->bindParam(':other', $other);

  if ($stmt->execute()) {
    echo "成功插入数据到数据库";
  } else {
    $errorInfo = $stmt->errorInfo();
    echo "插入数据时出现错误: " . $errorInfo[2];
  }

  $conn = null; // 关闭数据库连接
} catch (PDOException $e) {
  echo "连接数据库时发生错误: " . $e->getMessage();
}
?>